package cn.wolfcode.luowowo.comment.service.impl;

import cn.wolfcode.luowowo.comment.domain.ScenicComment;
import cn.wolfcode.luowowo.comment.domain.ScenicCommentReply;
import cn.wolfcode.luowowo.comment.repository.ScenicCommentMongoRepository;
import cn.wolfcode.luowowo.comment.repository.ScenicCommentReplyMongoRepository;
import cn.wolfcode.luowowo.comment.service.IScenicCommentReplyService;
import cn.wolfcode.luowowo.comment.service.IScenicCommentService;
import cn.wolfcode.luowowo.common.query.ScenicQueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@Service
public class ScenicCommentReplyServiceImpl implements IScenicCommentReplyService {

    @Autowired
    private ScenicCommentReplyMongoRepository replyRepository;
    @Autowired
    private ScenicCommentMongoRepository commentRepository;


    public AjaxResult save(ScenicCommentReply commentReply) {
        AjaxResult result = new AjaxResult();

        //新增评论
        commentReply.setCreateTime(new Date());
        ScenicCommentReply scenicCommentReply = replyRepository.save(commentReply);

        //查询到大评论
        ScenicComment comment = commentRepository.findById(commentReply.getParentId()).get();
        List<ScenicCommentReply> list = comment.getRefComment();
        list.add(scenicCommentReply);
        comment.setRefComment(list);
        commentRepository.save(comment); //更新大评论

        return result;
    }

}
